<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script type="text/javascript">
    /*
     *创建一个对象
     */
    /*
    var obj =
    {
        name:"孙悟空",
        age:18,
        gender:"男",
        sayName:function()
        {
            alert(this.name);
        }
    };

    var obj2 =
    {
        name:"猪八戒",
        age:28,
        gender:"男",
        sayName:function()
        {
            alert(this.name);
        }
    };

    var obj3 =
    {
        name:"沙和尚",
        age:38,
        gender:"男",
        sayName:function()
        {
            alert(this.name);
        }
    };
    obj.sayName();
    obj2.sayName();
    obj3.sayName();
    */
    //通过工厂方法创建对象
    //通过该方法可以大批量的创建对象
    function createPerson(name,age,gender)
    {
        //在函数中创建一个新的对象
        var obj =new Object();
        //向对象中添加属性
        obj.name="孙悟空";
        obj.age=18;
        obj.gender="男";
        //将新的对象返回
        return obj;
    }
    var obj2 =createPerson("孙悟空",18,"男");                                                                                           
    console.log(obj2);

    function createDog(name,age)
    {
        var obj=new Object();
        obj.name=name;
        obj.age=age;
        obj.sayHello=function()
        {
            alert(this.name);
        };
        return obj;
    }
    var obj3 =createDog("李爱林",3);
    console.log(obj3);
    //使用工厂方法创建的对象，使用的构造函数都是Object
    //所以创建的对象都是Object这个类型
    //就导致我们无法区分出多种不同类型的对象
    </script>
</head>
<body>
    
</body>
</html>